// 我的购物车
function myCart() {
    let data = Mock.mock({
        /*"shopList|2": [{
            "shopName": "@ctitle(5)",
            "cupcom": true,
            "shopId|1-1000000": 1,
            "proList|1-3": [{
                "img": '@image("1000x1000","@hex()")',
                "name": "@ctitle(5)",
                "property": "@csentence(15)",
                "price|1-100": 1,
                "tag": "@ctitle(2)",
                "tagColor":"@hex()",
                "proId|1-1000000":1
            }]
        }]*/
    });
    Vue.filter('keepTwoNum', function(value) {
        value = Number(value);
        return value.toFixed(2);
    });

    new Vue({
        el: "#myCart",
        data() {
            return {
                buynum: 1,
                shopList: [],
                allCheckeds: false,
                allBuyNum: 0, //购买商品总数量
                allBuyPrice: 0, //购买商品总价
                dialogTableVisible: false, //优惠券弹出层flag
                dialogFormVisible: false, //修改尺码弹出层flag
                couponInfo: [], //优惠券列表信息
                productColorAndSize: [{
                    productColorSizeList: [], //尺寸集合
                    colorCoverPic: '', //图片
                }], //商品颜色尺寸信息
                product: {}, //当前选中的商品信息
                productColor: {}, //获取颜色
                productColorIndex: 0, //颜色下标
                productSize: {}, //获取尺码
                productSizeIndex: 0, //尺码下标
                selectcart : []//被选中的购物车 店铺id key value是选中购物商品
            }
        },
        methods: {
            // 拉取购物车信息
            getCartInfo: function() {
                let that = this;
                axios({
                        method: 'post',
                        url: urlParam.domain() + '/api/shoppingCart/queryShoppingCarts',
                        data: formartPostParms({
                            token: urlParam.token()
                        })
                    })
                    .then(function(response) {
                        that.shopList = response.data.data;
                    });

            },

            //删除单个商品
            deleteProduct: function(sindex, index, cartId) {
                let that = this;
                axios({
                        method: 'post',
                        url: urlParam.domain() + '/api/shoppingCart/deleteOneProduct?cartId=' + cartId,
                        data: formartPostParms({
                            token: urlParam.token()
                        })
                    })
                    .then(function(response) {
                        that.shopList[sindex].productList.splice(index, 1);
                        if (that.shopList[sindex].productList.length == 0) {
                            that.shopList.splice(sindex, 1);
                        }
                        that.$message({
                            showClose: true,
                            message: '操作成功',
                            type: 'success'
                        });
                    });
            },

            //删除所有商品
            deleteAllProduct: function() {
                let count = 0;
                let arr = new Array();
                for (let shop of this.shopList) {
                    for (let product of shop.productList) {
                        if (product.productChecked) {
                            arr.push(product.cartId);
                            count++;
                        }
                    }
                }
                if (count == 0) {
                    alert("未选中商品")
                    return
                }
                let that = this;
                axios({
                        method: 'post',
                        url: urlParam.domain() + '/api/shoppingCart/deleteBatchProduct?cartIds=' + arr,
                        data: formartPostParms({
                            token: urlParam.token()
                        })
                    })
                    .then(function(response) {
                        window.location.reload();
                        that.$message({
                            showClose: true,
                            message: '操作成功',
                            type: 'success'
                        });
                    });
            },

            //获取购买数量
            getBuyNumber(val, shopIndex, productIndex) {
                var that = this;
                this.shopList[shopIndex].productList[productIndex].buyNumber = val;
                let cartId = this.shopList[shopIndex].productList[productIndex].cartId;
                // this.productSizeIndex = productIndex;
                this.updateCat(this.product.productPrice);
                //获取总购买数量
                this.getAllBuyNum();

            },

            //全选
            allChecked: function() {
                if (this.allCheckeds) {
                    for (let shop of this.shopList) {
                        shop.shopChecked = false;
                        for (let product of shop.productList) {
                            product.productChecked = false;
                        }
                    }
                } else {
                    for (let shop of this.shopList) {
                        shop.shopChecked = true;
                        for (let product of shop.productList) {
                            product.productChecked = true;
                        }
                    }
                }
                this.getSelect();
                //获取总购买数量
                this.getAllBuyNum();
            },

            //店铺的全选
            changeShopProducts: function(sindex) {
                let count = 0;
                let sellerId = 0;
                if (this.shopList[sindex].shopChecked) {
                    for (let item of this.shopList[sindex].productList) {
                        sellerId = item.sellerId;
                        item.productChecked = false;
                    }
                } else {
                    this.allCheckeds = true;
                    for (let item of this.shopList[sindex].productList) {
                        item.productChecked = true;
                    }
                }

                for (let shop of this.shopList) {
                    if (shop.shopChecked) count++;
                }
                this.allCheckeds = count == this.shopList.length;
                this.getSelect();
                //获取总购买数量
                this.getAllBuyNum();
            },

            //商品的选择
            changeProducts: function(sindex, index) {
                var flag = this.shopList[sindex].productList[index].productChecked;
                this.shopList[sindex].productList[index].productChecked = flag ? false : true;
                let arr = new Array();
                let count = 0;
                let shopCount = 0;
                let sellerId = 0;
                for (var i = 0; i < this.shopList[sindex].productList.length; i++) {
                    var product = this.shopList[sindex].productList[i];
                    if (product.productChecked) {
                        count++;
                        sellerId = product.sellerId;
                        arr.push(i);
                    }
                }
                this.shopList[sindex].shopChecked = count == this.shopList[sindex].productList.length
                for (let shop of this.shopList) {
                    if (shop.shopChecked) shopCount++;
                }
                this.allCheckeds = shopCount == this.shopList.length;

                for (let a of arr) {
                    this.shopList[sindex].productList[a].productChecked = true;
                }

                this.getSelect()
                //获取总购买数量
                this.getAllBuyNum();
            },
            /**
             * 将选中商品加入已购买商品
             */
            getSelect(){
                var that = this;
                //清空数组
                that.selectcart = [];
                this.shopList.forEach(function (shop,index) {
                    var pList = [];
                    for (let product of shop.productList) {
                        if (product.productChecked)
                            pList.push(product);
                    }
                    if (pList.length)
                        that.selectcart.push(pList) ;
                    console.log(that.selectcart)
                })
            },


            //获取总购买数量
            getAllBuyNum: function() {
                let num = 0;
                let price = 0;
                for (let shop of this.shopList) {
                    for (let product of shop.productList) {
                        if (product.productChecked) { //商品为选中状态
                            num = num - (-product.buyNumber);
                            price = product.buyNumber * product.productPrice + price;
                            product.productAmount = product.buyNumber * product.productPrice;
                        }
                    }
                }
                this.allBuyNum = num;
                this.allBuyPrice = price;
                console.log("allBuyNum" + this.allBuyNum);
                //console.log("allBuyPrice"+this.allBuyPrice);
            },

            //单个商品移入我的收藏
            addProductFollow: function(sindex, index, productId, cartId) {
                let that = this;
                axios({
                        method: 'get',
                        url: urlParam.domain() + '/api/productFollow/save',
                        params: {
                            token: urlParam.token(),
                            productId: productId,
                            type: 0
                        }
                    })
                    .then(function(response) {
                        that.deleteProduct(sindex, index, cartId);
                    });
            },

            //多个商品移入我的收藏
            addAllProductFollow: function() {
                let count = 0;
                let that = this;
                let arr = new Array();
                for (let shop of this.shopList) {
                    for (let product of shop.productList) {
                        if (product.productChecked) {
                            arr.push(product.productNumber);
                            count++;
                        }
                    }
                }
                console.log("-----" + arr);
                if (count == 0) {
                    alert("未选中商品")
                    return
                }
                axios({
                        method: 'get',
                        url: urlParam.domain() + '/api/productFollow/allSave?productIds=' + arr,
                        params: {
                            token: urlParam.token(),
                            type: 0
                        }
                    })
                    .then(function(response) {
                        that.deleteAllProduct();
                    });
            },

            //获取优惠券列表
            getCouponList: function(businessId) {
                let that = this;
                axios({
                        method: 'get',
                        url: urlParam.domain() + '/api/myCoupon/couponList',
                        params: {
                            token: urlParam.token(),
                            businessId: businessId
                        },
                    })
                    .then(function(response) {
                        console.log(response);
                        if (response.data.data.length == 0) {
                            that.$notify({
                                title: '警告',
                                message: '此店铺没有优惠券',
                                type: 'warning'
                            });
                        }
                        if (response.status != 200) {
                            that.$message({
                                title: '消息',
                                message: response.data.message,
                            });
                        }
                        that.dialogTableVisible = true;
                        that.couponInfo = response.data.data;

                    });
            },
            //点击获取优惠券
            couponEdit(scope, businessId) {
                let that = this;
                axios({
                    url: urlParam.domain() + "/api/myCoupon/getCoupons",
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        StartTime: scope.startTime,
                        businessId: businessId,
                        couponNo: scope.couponNo,
                        couponType: scope.couponType,
                        endTime: scope.endTime,
                        numberLimit: 0
                    }
                }).then(result => {
                    that.$message({
                        title: '消息',
                        message: result.data.message,
                    });
                    that.dialogTableVisible = false;
                })

            },
            updateSpec: function(pro) {
                var that = this;
                this.product = pro;
                axios({
                    url: urlParam.domain() + "/api/productInfo/productColorAndSize",
                    method: "post",
                    params: {
                        token: urlParam.token(),
                        productId: pro.productId,
                    }
                }).then(result => {
                    if (result.status != 200) {
                        that.$message({
                            title: '消息',
                            message: result.data.message,
                        });
                    }
                    that.productColorAndSize = result.data.data;
                    that.productColorAndSize.forEach(function(value, cIndex) {
                        if (value.colorName == that.product.colorName) {
                            that.productColorIndex = cIndex;
                            value.productColorSizeList.forEach(function(values, sIndex) {
                                if (values.name == that.product.sizeName) {
                                    that.productSizeIndex = sIndex;
                                }
                            });

                        }
                    });
                    that.clickColor(that.productColorIndex);
                    // that.clickSize(that.productSize);
                    that.dialogFormVisible = true;
                });
            },
            //鼠标点击选择颜色
            clickColor(productColor) {
                //赋值当前选中颜色
                this.productColorIndex = productColor;
                this.productColor = this.productColorAndSize[productColor];
                //赋值尺寸集合
                this.productSize = this.productColorAndSize[productColor].productColorSizeList;

            },
            //鼠标点击选择尺寸
            clickSize(productSize) {
                //赋值当前选中尺寸
                this.productSizeIndex = productSize;
            },
            //更新购物车
            updateShoppingcat() {
                this.updateCat(this.productSize[this.productSizeIndex].price);
                this.dialogFormVisible = false
            },
            //点击提交
            goPay() {
                //判断登陆
                userLogin.ifLogin();
                console.log(JSON.stringify(this.selectcart));
                sessionStorage.setItem("selectProduct", JSON.stringify(this.selectcart));
                window.location.href = "../../html/cart/cart_confirm.html";
            },
            updateCat(price) {
                var that = this;
                this.product.colorName = this.productColor.colorName;
                this.product.sizeName = this.productSize[this.productSizeIndex] ? this.productSize[this.productSizeIndex].name : "";
                this.product.productPrice = price;
                //更新购物车
                axios.post(
                    urlParam.domain() + "/api/shoppingCart/updateShoppingCart",
                    JSON.stringify([{
                        productPrice: that.product["productPrice"],
                        buyNumber: that.product["buyNumber"],
                        cartId: that.product["cartId"],
                        colorName: that.product["colorName"],
                        sizeName: that.product["sizeName"]
                    }]), { headers: { "Content-Type": "application/json" } })
                    .then(result => {
                        console.log(result)
                    })
                    .catch(err => {
                        console.log(err)
                    })
            }
        },
        components: {
            counter,

        },
        created() {
            this.getCartInfo();
        }
    })
}

// 我的购物车
function cart_comfirm() {
    cart_comfirm = new Vue({
        el: "#cart_comfirm",
        data() {
            return {
                area: area, //省市区 josn <script src="../../lib/js/area.js"></script> 引入
                cityList: [], //市 生成选项的数组
                areaList: [], //区 生成选项的数组
                provinceIndex: -1, //省对应的数组下标
                cityIndex: -1, //市对应的数组下标
                addressForm : {
                    provinceName: -1, //当前选择的省
                    cityName: -1, //当前选择的市
                    areaName: -1, //当前选择的区
                    name : '',//收货人
                    phone : '',//手机
                    addInfo : '',//详细地址
                    default : false,//设置默认值
                },
                tagAddress:1,//用于切换 展示、收起 收货地址 0 收起 1 展开
                address: [], //收货地址
                shipmentPriceList: [],
                productList : JSON.parse(sessionStorage.getItem("selectProduct")),//选中商品集合
                productIds : "",//选中商品编号
                addressIdActive: 0,//当前选中地址id
                shipmentPriceList : {},//运费 key 店铺id value 运费
                money : {
                    countNumber : 0,//总件数
                    countShipment : 0, //总运费
                    countMoney :0,//总价格
                    allMoney : 0,//实付价格
                },
                showBilling: false,

                couponList: [], //优惠券集合
                couponIdActive: new Map(),//选中的优惠券id key: 商家id value 优惠券对象,
                showDialog: false,
                dialogType: -1,
                remarks : '',//备注
                invoiceForm :{
                    invoiceType: 1,
                    invoiceTitle: "",
                    taxpayerNumber: "",
                    telephone: "",
                    email: "",
                },//发票信息

                rules:{
                    name : [
                        { required: true, message: '请输入收货人', trigger: 'blur' },
                    ],
                    phone : [
                        {validator:(rule,value,callback)=>{
                            console.log(value.length)
                              if (value === ''){
                                  callback(new Error("请输入手机"));
                              } else if (/^\d+$/.test(value) == false){
                                  callback(new Error("请输入数字"));
                              } else if (value.length > 11){
                                  callback(new Error("长度大于11位"));
                              }else {
                                  callback();
                              }
                        },trigger: 'blur'},
                    ],
                    provinceIndex :[
                        {validator:(rule,value,callback)=>{
                                if (this.provinceIndex === -1){
                                    this.$refs.addressForm.validateField("cityIndex");
                                    this.$refs.addressForm.validateField("areaName");
                                    callback(new Error("请选择省"));
                                } else {
                                    callback();
                                }
                            },trigger: 'change'},
                    ],
                    cityIndex:[
                        {validator:(rule,value,callback)=>{
                                if (this.cityIndex === -1){
                                    this.$refs.addressForm.validateField("areaName");
                                    callback(new Error("请选择市"));
                                } else {
                                    callback();
                                }
                            },trigger: 'change'},
                    ],
                    areaName:[
                        {validator:(rule,value,callback)=>{
                                if (this.addressForm.areaName === -1){
                                    callback(new Error("请选择区"));
                                } else {
                                    callback();
                                }
                            },trigger: 'change'},
                    ],
                    addInfo:[
                        { required: true, message: '请填写详细地址', trigger: 'blur' },
                    ],
                    invoiceTitle : [
                        {validator:(rule,value,callback)=>{
                                if (this.invoiceForm.invoiceType != 1){
                                    if (value === ''){
                                        callback(new Error("请输入发票抬头"));
                                    }else {
                                        callback();
                                    }
                                }
                            },trigger: 'blur'}
                    ],
                    taxpayerNumber : [
                        {validator:(rule,value,callback)=>{
                                if (this.invoiceForm.invoiceType != 1) {
                                    if (value === '') {
                                        callback(new Error("请输入纳税人编号"));
                                    } else if (/^\d+$/.test(value) == false) {
                                        callback(new Error("请输入数字"));
                                    }  else {
                                        callback();
                                    }
                                }
                            },trigger: 'blur'}
                    ],
                    telephone : [
                        {validator:(rule,value,callback)=>{
                                if (this.invoiceForm.invoiceType != 1) {
                                    if (value === '') {
                                        callback(new Error("请输入收票人手机"));
                                    } else if (/^\d+$/.test(value) == false) {
                                        callback(new Error("请输入数字"));
                                    } else if (value.length > 11) {
                                        callback(new Error("长度大于11位"));
                                    } else {
                                        callback();
                                    }
                                }
                            },trigger: 'blur'}
                    ],
                    email : [
                        {validator:(rule,value,callback)=>{
                                if (this.invoiceForm.invoiceType != 1) {
                                    if (value === '') {
                                        callback(new Error("请输入邮箱"));
                                    } else if ( /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/.test(value) == false) {
                                        callback(new Error("邮箱格式不正确"));
                                    } else {
                                        callback();
                                    }
                                }
                            },trigger: 'blur'}
                    ]
                },
            }
        },
        methods: {
            getData(){
                //判断有无登陆
                if (!userLogin.ifLogin()) return;
                //判断订单有没有支付订单信息
                if (this.productList == null){
                    //跳转首页
                    window.location.href = '../../html/index/index.html';
                }
                var ids = [];
                var then = this;
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/user/myAddress',
                    params : {
                        token : urlParam.token(),
                        pageSize : 5,
                    },
                }).then(result=>{
                    var array = result.data.data;
                    if (then.length != 0) {
                        //获取收货地址
                        then.address = array;
                        if(then.address.length>6){
                            then.tagAddress=0;
                        }
                        //设置收货地址焦点
                        then.addressIdActive = 0;
                    }
                })

                console.log(this.productList);
                //组装productIds
                this.productList.forEach(function (shop) {
                    console.log("----------------")
                    console.log(shop)
                    //商家id
                    var sellerId = 0;
                    var productId = [];
                    shop.forEach(function (product) {
                        sellerId = product.sellerId;
                        productId.push(product.productNumber);
                        //获取总价格
                        then.money.countMoney += product.productAmount;
                        //获取总数量
                        then.money.countNumber += product.buyNumber;
                        //如果没有定义返回0
                        if (!then.money["\""+sellerId+"\""]){
                            then.money["\""+sellerId+"\""] = 0;
                        }
                        //店铺总价
                        then.money["\""+sellerId+"\""] += product.productAmount;
                    });
                    axios({
                        url : urlParam.domain() + "/api/myCoupon/myCouponList",
                        params : {
                            token : urlParam.token(),
                            total : then.money["\""+sellerId+"\""],
                            businessId : sellerId,
                            productNos : productId.join(),
                            type : 0
                        },
                        method : "get"
                    }).then(result=>{
                        console.log(result);
                        var coupon = [];
                        result.data.data.forEach(value=>{
                           if(value.useCondition < then.money["\""+sellerId+"\""]){
                               coupon.push(value);
                           }
                        });
                        then.couponList = coupon;
                    })
                    //数组合并
                    ids = [...ids,...productId];
                });
                console.log(then.money);
                //将数组转成逗号分隔
                this.productIds = ids.join();
                //获取下单信息
                axios({
                    url: urlParam.domain() + "/api/buy/checkout",
                    method: 'get',
                    params: {
                        token: urlParam.token(),
                        productNumbers: this.productIds
                    },
                    responseType: "stream"
                }).then(result => {
                    result.data.data.shipmentPriceList.forEach(value => {
                        //设置店铺运费
                        then.shipmentPriceList["\"" + value.sellerId + "\""] = value.shipmentPrice;
                        //获取总价格
                        then.money.countMoney += value.shipmentPrice;
                        //获取总运费
                        then.money.countShipment += value.shipmentPrice;
                    });
                    then.money.allMoney = then.money.countMoney;
                });

            },
            //点击切换 展开、收起 收货地址
            clickTagAddress(){
                this.tagAddress==0?this.tagAddress=1:this.tagAddress=0;
            },
            // 收货地址选择效果
            shippingCheck(val) {
                this.addressIdActive = val;
            },
            // 展开折叠发票信息
            invoiceExpand(num) {
                this.invoiceForm.invoiceType = num;
            },
            // 展开折叠优惠券
            billingTicketExpand() {
                this.showBilling = !this.showBilling;
            },
            // 优惠券选择
            billingTicket(val,sellerId) {
                this.couponIdActive.set(sellerId,val);
                if (this.money.allMoney <= val.faceValue){
                    this.money.allMoney = 0;
                }else{
                    this.money.allMoney = this.money.countMoney;
                    this.money.allMoney -= val.faceValue;
                }
            },
            // 添加新地址
            openAddressDialog() {
                this.showAddress = true;
            },
            // 打开弹窗
            openDialog(type) {
                this.showDialog = true;
                this.dialogType = type;
            },
            // 关闭弹窗
            closeDialog() {
                this.showDialog = false;
                this.dialogType = -1;
            },
            //点击提交默认
            submitAddress(addressForm){
                userLogin.ifLogin();
                var that = this;
                that.$refs[addressForm].validate((valid) => {
                    if (valid) {
                        axios({
                            url: urlParam.domain() + "/api/user/addressCreate",
                            method: 'post',
                            params: {
                                token : urlParam.token(),
                                cityName : that.addressForm.cityName,
                                defalutFlag : that.addressForm.default ? 1 : 0,
                                provinceName : that.addressForm.provinceName,
                                districtName : that.addressForm.areaName,
                                userAdress : that.addressForm.addInfo,
                                userName : that.addressForm.name,
                                userPhone : that.addressForm.phone
                            },
                        }).then(result => {
                            console.log(result);
                            that.address.forEach(value=>{
                                value.defalutFlag == 1 ? value.defalutFlag = 0 : value.defalutFlag = 0;
                            })
                            //设置初始值
                            that.addressForm = {
                                provinceName: -1, //当前选择的省
                                    cityName: -1, //当前选择的市
                                    areaName: -1, //当前选择的区
                                    name : '',//收货人
                                    phone : '',//手机
                                    addInfo : '',//详细地址
                                    default : false,//设置默认值
                            }
                            that.address.push(result.data.data);
                            this.addressIdActive = that.address.length-1;
                            this.showDialog = false;
                            this.dialogType = -1;
                            that.$message({
                                message: '添加成功！',
                                type: 'success'
                            });
                        });
                    } else {
                        return false;
                    }
                });
                console.log(this.addressForm);
            },
            //点击提交订单
            submit(formName) {
                var product = {};
                var then = this;
                var productName = [];
                product.addressId = this.address[this.addressIdActive].addressId;
                product.payAmount = this.money.allMoney;
                product.orderList = [];
                this.productList.forEach(value => {
                    var obj = {};
                    var productNumber = 0;//商品总数
                    var sellerId = 0;//商家id
                    var groupPurchaseActivityId = null; //团购id
                    obj.orderProducts = [];//订单明细
                    value.forEach(product => {
                        var pro = product;
                        sellerId = product.sellerId;
                        productNumber += product.buyNumber;
                        obj.orderProducts.push(pro);
                        productName.push(product.name);
                    });
                    obj.buyNumber = productNumber;
                    obj.groupPurchaseActivityId = groupPurchaseActivityId;//团购id
                    obj.invoiceType = then.invoiceForm.invoiceType;//发票类型
                    if (then.invoiceForm.invoiceType != 1){
                        obj.orderInvoice = {};
                        obj.orderInvoice.email = then.invoiceForm.email;
                        obj.orderInvoice.invoiceTitle = then.invoiceForm.invoiceTitle;
                        obj.orderInvoice.taxpayerNumber = then.invoiceForm.taxpayerNumber;
                        obj.orderInvoice.telephone = then.invoiceForm.telephone;
                    }
                    obj.orderAmount = then.money["\"" + sellerId + "\""];
                    obj.orderType = product.orderType || 0;//订单类型
                    obj.remarks = then.remarks;
                    obj.sellerId = sellerId;
                    obj.shipmentAmount = then.shipmentPriceList["\"" + sellerId + "\""];
                    obj.couponId = then.couponIdActive.get(sellerId) ? then.couponIdActive.get(sellerId).id : 0;
                    //优惠券抵用价格
                    var couponVal = then.couponIdActive.get(sellerId) ? then.couponIdActive.get(sellerId).faceValue : 0;
                    obj.payAmount = (obj.shipmentAmount + obj.orderAmount - couponVal) < 0 ? 0 : (obj.shipmentAmount + obj.orderAmount - couponVal).toFixed(2);
                    product.orderList.push(obj);
                });
                console.log(JSON.stringify(product));
                //更新购物车
                axios({
                    method:"post",
                    url:urlParam.domain() + "/api/buy/confirm?token="+urlParam.token(),
                    data:JSON.stringify(product),
                    headers: { "Content-Type": "application/json"}
                }).then(function (result) {
                    //清除商品
                    sessionStorage.removeItem("selectProduct");
                    window.location.href = "../../html/usercenter/shopCart.html?orderPayNumber="+result.data.data;
                })
            },

        },
        created() {
            this.getData();
        },

        watch: {
            // 监听省发生变化
            provinceIndex: {
                handler: function() {
                    //清空市和区
                    this.cityList = [];
                    this.areaList = [];
                    this.addressForm.cityName = -1;
                    if (this.provinceIndex != -1){
                        //赋值当前的省id
                        this.addressForm.provinceName = area[this.provinceIndex].areaname;
                        //获取当前省的下级市
                        this.cityList = area[this.provinceIndex].datas;
                    }else {
                        this.cityIndex = -1;
                        this.addressForm.areaName = -1;
                    }

                },
            },
            // 监听市发生变化
            cityIndex: {
                handler: function() {
                    //清空区
                    this.areaList = [];
                    this.addressForm.areaName = -1;
                    if (this.cityIndex != -1){
                        //赋值当前的区id
                        this.addressForm.cityName = this.cityList[this.cityIndex].areaname;
                        //获取当前市的下级区
                        this.areaList = this.cityList[this.cityIndex].datas;
                    }else {
                        this.addressForm.areaName = -1;
                    }
                },
            }
        }
    })
}